//
//  JMGreenDegraView.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/5/5.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMGreenDegraView.h"

@implementation JMGreenDegraView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        CGFloat labelX = 15;
        CGFloat labelW = 100;
        CGFloat labelH = 30;
        UILabel *pineNutLab = [ARC createLabelWithFrame:CGRectMake(labelX, 0, labelW, labelH) Font:BYPiFont Text:@"现有松籽:"];
        self.pineNutLab = pineNutLab;
        [self addSubview:pineNutLab];
        UILabel *pineNutNum = [ARC createLabelWithFrame:CGRectMake(105, 0, labelW, labelH) Font:BYPiFont Text:@""];
        self.pineNutNum = pineNutNum;
        [self addSubview:pineNutNum];
        
        UILabel *existGreenLab = [ARC createLabelWithFrame:CGRectMake(labelX, labelH, 100, labelH) Font:BYPiFont Text:@"现有绿松果:"];
        self.existGreenLab = existGreenLab;
        [self addSubview:existGreenLab];
        UILabel *existGreenNum = [ARC createLabelWithFrame:CGRectMake(105, labelH, 100, labelH) Font:BYPiFont Text:@""];
        self.existGreenNum = existGreenNum;
        [self addSubview:existGreenNum];
        
        UILabel *needGreenLab= [ARC createLabelWithFrame:CGRectMake(labelX, labelH*2, 100, labelH) Font:BYPiFont Text:@"需要绿松果:"];
        self.needGreenLab = needGreenLab;
        [self addSubview:needGreenLab];
        
        
        UILabel *needGreenNum= [ARC createLabelWithFrame:CGRectMake(105, labelH*2, 100, labelH) Font:BYPiFont Text:@""];
        self.needGreenNum = needGreenNum;
        [self addSubview:needGreenNum];
        
        UILabel *afDownPNutLab = [ARC createLabelWithFrame:CGRectMake(labelX, labelH*3, 100, labelH) Font:BYPiFont Text:@"降级后松籽:"];
        self.afDownPNutLab = afDownPNutLab;
        [self addSubview:afDownPNutLab];
        
        UILabel *afDownPNutNum = [ARC createLabelWithFrame:CGRectMake(105, labelH*3, 100, labelH) Font:BYPiFont Text:@""];
        self.afDownPNutNum = afDownPNutNum;
        [self addSubview:afDownPNutNum];
        
        
        UILabel *afDownPGreenLab = [ARC createLabelWithFrame:CGRectMake(labelX, labelH*4, 100, labelH) Font:BYPiFont Text:@"降级后绿松果:"];
        self.afDownPGreenLab = afDownPGreenLab;
        [self addSubview:afDownPGreenLab];
        
        UILabel *afDownPGreenNum = [ARC createLabelWithFrame:CGRectMake(105, labelH*4, 100, labelH) Font:BYPiFont Text:@""];
        self.afDownPGreenNum = afDownPGreenNum;
        [self addSubview:afDownPGreenNum];
 
        
        
        UILabel *paymentPwdLab = [ARC createLabelWithFrame:CGRectMake(labelX, labelH*5, 100, labelH) Font:BYPiFont Text:@"支付密码:"];
        self.paymentPwdLab = paymentPwdLab;
        [self addSubview:paymentPwdLab];
        
//        UITextField *paymentPwdNum = [ARC createTextFieldWithFrame:CGRectMake(105, labelH*5, 150, labelH) Font:BYPiFont-1 Placeholder:@"请输入支付密码" SecureTextEntry:NO];

        JMTextField *paymentPwdNum = [JMTextField createTextFieldWithFrame:frame
                                                                      Font:BYPiFont
                                                               Placeholder:@"请输入支付密码"
                                                           SecureTextEntry:YES
                                                                 TextColor:[UIColor blackColor]];
    
        paymentPwdNum.keyboardType =  UIKeyboardTypeDefault;
        paymentPwdNum.frame =CGRectMake(105, labelH*5, 150, labelH);
        paymentPwdNum.borderStyle = UITextBorderStyleRoundedRect;
        paymentPwdNum.clearsOnBeginEditing=YES;
        self.paymentPwdNum = paymentPwdNum;
        [self addSubview:paymentPwdNum];
        
        
        
        UILabel *titleLab = [ARC createLabelWithFrame:CGRectMake(labelX, labelH*6+20, 320, 20) Font:BYPiFont-1 Text:@"降级规则:"];
        self.titleLabel = titleLab;
        [self addSubview:titleLab];
        
        
        UILabel *firstLab = [ARC createLabelWithFrame:CGRectMake(labelX, labelH*7+10, 305, 40) Font:BYPiFont-2 Text:@"1.每次降级一个松果可获得1000松籽来补齐亏欠的松籽，剩余的松籽可作为可提现的松籽库存"];
        self.firstTitlL = firstLab;
        
        firstLab.textAlignment = NSTextAlignmentCenter;
        firstLab.lineBreakMode = NSLineBreakByWordWrapping;
        firstLab.numberOfLines = 0;
        [self addSubview:firstLab];
        
       
//        UILabel *secondLab = [ARC createLabelWithFrame:CGRectMake(labelX, labelH*5+20, 320, 20) Font:BYPiFont-1 Text:@"2.红松果降级只能用未绑定的库存"];
//        self.secondTitlL = secondLab;
//        [self addSubview:secondLab];
        
        
        
        self.pineNutLab.textColor = [UIColor blackColor];
        self.pineNutNum.textColor = [UIColor blackColor];
        self.existGreenLab.textColor = [UIColor blackColor];
        self.existGreenNum.textColor = [UIColor blackColor];
        self.needGreenLab.textColor = [UIColor blackColor];
        self.needGreenNum.textColor = [UIColor blackColor];
        
        self.afDownPNutLab.textColor = [UIColor blackColor];
        self.afDownPNutNum.textColor = [UIColor blackColor];
        self.afDownPGreenLab.textColor = [UIColor blackColor];
        self.afDownPGreenNum.textColor = [UIColor blackColor];
        self.paymentPwdLab.textColor = [UIColor blackColor];
        self.paymentPwdNum.textColor = [UIColor blackColor];
        
        
        
        self.totalPrice.textColor = [UIColor blackColor];
        self.totalNum.textColor = [UIColor blackColor];
        self.titleLabel.textColor = [UIColor grayColor];
        self.firstTitlL.textColor = [UIColor grayColor];
        self.secondTitlL.textColor = [UIColor grayColor];
        
        
        self.pineNutLab.textAlignment = NSTextAlignmentLeft;
        self.pineNutNum.textAlignment = NSTextAlignmentLeft;
        self.existGreenLab.textAlignment = NSTextAlignmentLeft;
        self.existGreenNum.textAlignment = NSTextAlignmentLeft;
        self.needGreenLab.textAlignment = NSTextAlignmentLeft;
        self.needGreenNum.textAlignment = NSTextAlignmentLeft;
        self.afDownPNutLab.textAlignment = NSTextAlignmentLeft;
        self.afDownPNutNum.textAlignment = NSTextAlignmentLeft;
        self.afDownPGreenLab.textAlignment =NSTextAlignmentLeft;
        self.afDownPGreenNum.textAlignment =NSTextAlignmentLeft;
        self.paymentPwdLab.textAlignment = NSTextAlignmentLeft;
        self.paymentPwdNum.textAlignment = NSTextAlignmentLeft;
        self.totalPrice.textAlignment = NSTextAlignmentLeft;
        self.totalNum.textAlignment = NSTextAlignmentLeft;
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.firstTitlL.textAlignment = NSTextAlignmentLeft;
        self.secondTitlL.textAlignment = NSTextAlignmentLeft;
        
        self.pineNutLab.frame = [ToolViewAndData MyAutoLayout:self.pineNutLab];
        self.pineNutNum.frame = [ToolViewAndData MyAutoLayout:self.pineNutNum];
        self.existGreenLab.frame = [ToolViewAndData MyAutoLayout:self.existGreenLab];
        self.existGreenNum.frame = [ToolViewAndData MyAutoLayout:self.existGreenNum];
        self.needGreenLab.frame = [ToolViewAndData MyAutoLayout:self.needGreenLab];
        self.needGreenNum.frame = [ToolViewAndData MyAutoLayout:self.needGreenNum];
        self.afDownPNutLab.frame =[ToolViewAndData MyAutoLayout:self.afDownPNutLab];
        self.afDownPNutNum.frame = [ToolViewAndData MyAutoLayout:self.afDownPNutNum];
        self.afDownPGreenLab.frame =[ToolViewAndData MyAutoLayout:self.afDownPGreenLab];
        self.afDownPGreenNum.frame =[ToolViewAndData MyAutoLayout:self.afDownPGreenNum];
        self.paymentPwdLab.frame = [ToolViewAndData MyAutoLayout:self.paymentPwdLab];
        self.paymentPwdNum.frame = [ToolViewAndData MyAutoLayout:self.paymentPwdNum];
        self.totalPrice.frame =[ToolViewAndData MyAutoLayout:self.totalPrice];
        self.totalNum.frame = [ToolViewAndData MyAutoLayout:self.totalNum];
        self.titleLabel.frame =[ToolViewAndData MyAutoLayout:self.titleLabel];
        self.firstTitlL.frame =[ToolViewAndData MyAutoLayout:self.firstTitlL];
        self.secondTitlL.frame =[ToolViewAndData MyAutoLayout:self.secondTitlL];
        
        [self setupData];
        
    }
    return self;
}
-(void)setupData
{
    UserEntity *user = [UserEntity shardUserInfo];
    self.pineNutNum.text = user.PineNut;
    self.existGreenNum.text = user.PineConeGreen;
    if ([self.pineNutNum.text intValue]<0) {
        self.needGreenNum.text = [NSString stringWithFormat:@"%d",[self.pineNutNum.text integerValue]/1000+1];
        self.afDownPNutNum.text = [NSString stringWithFormat:@"%d",1000-[self.pineNutNum.text integerValue]%1000];
        self.afDownPGreenNum.text = [NSString stringWithFormat:@"%d",[self.existGreenNum.text integerValue]-[self.needGreenNum.text integerValue]];
    }else{
        self.needGreenNum.text = @"0";
        self.afDownPNutNum.text = self.pineNutNum.text;
        self.afDownPGreenNum.text = self.existGreenNum.text;
    }
}
@end